package com.app.tool;


import com.jiangdg.usbcamera.utils.Lf_Debug;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class TypeC { 
	
	public final static int TDEA_ENCRYPT =           0x01;
	public final static int TDEA_DECRYPT =           0x00;
	/* RSA public and private key. */
	final static int MIN_RSA_MODULUS_BITS =   508;
	final static int MAX_RSA_MODULUS_BITS =   2048;
	final static int MAX_RSA_MODULUS_LEN  =   ((MAX_RSA_MODULUS_BITS + 7) / 8);
	final static int MAX_RSA_PRIME_BITS  =    ((MAX_RSA_MODULUS_BITS + 1) / 2);
	final static int MAX_RSA_PRIME_LEN   =    ((MAX_RSA_PRIME_BITS + 7) / 8);

	
	public class R_RSA_PUBLIC_KEY
	{
	    public int   bits;               /* length in bits of modulus */
	    public char[]  modulus = new char[MAX_RSA_MODULUS_LEN];   /* modulus */
	    public char[]  exponent = new char[4];           /* public exponent */
	};
	
	//时间相关
    public static void sys_DelayMs(int duration_ms)
    {
        try {
        	Thread.sleep(duration_ms);
        } 
        catch (InterruptedException e) 
        {
        	e.printStackTrace();
			Lf_Debug.e_printf(Lf_Debug._FILE_LINE_FUNC_(), e);
        }
    }
	
    public static void sys_GetTime(char[] time)
    {
    	Date now = new Date();   
   	  	SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss", Locale.getDefault());   
   	    byte[] stime = BytesUtil.hex2byte(sdf.format(now));   
    	for(int i=0; i<7; i++)
    	{
    		time[i] = (char)stime[i];
    	}
    }
    
    public static long sys_GetCounter()
    {
        return System.currentTimeMillis();
    }
    
    public static void memcpy(char[] dest, char[] src, int len)
    {
    	System.arraycopy(src, 0, dest, 0, len);
    }
    
    public static void memcpy(char[] dest, int dpos, char[] src, int len)
    {
    	System.arraycopy(src, 0, dest, dpos, len);
    }
    
    public static void memcpy(char[] dest, char[] src, int spos, int len)
    {
    	System.arraycopy(src, spos, dest, 0, len);
    }
    
    public static void memcpy(char[] dest, int dpos, char[] src, int spos, int len)
    {
    	System.arraycopy(src, spos, dest, dpos, len);
    }
    
    public static void memset(char[] dest, char dpos, int len)
    {
    	for(int i=0; i<len; i++)
    	{
    		dest[i] = dpos;
    	}
    }
    
    public static void memset(char[] dest, int dpos, int len)
    {
    	for(int i=0; i<len; i++)
    	{
    		dest[i] = (char)dpos;
    	}
    }
    
    public static void memset(short[] dest, int dpos, int len)
    {
    	for(int i=0; i<len; i++)
    	{
    		dest[i] = (short)dpos;
    	}
    }
    
    public static void memset(char[] dest, int doffset, int dpos, int len)
    {
    	for(int i=doffset; i<len; i++)
    	{
    		dest[i] = (char)dpos;
    	}
    }
    
    public static boolean memcmp(char[] dest, char[] src, int len)
    {
    	for(int i=0; i<len; i++)
    	{
    		if(dest[i] != src[i])
    		{
    			return true;
    		}
    	}
    	return false;
    }
    
    public static boolean memcmp(char[] dest, int dpos, char[] src, int len)
    {
    	if(dest.length > len
    	  ||src.length > len)
    	{
    		return true;
    	}
    	for(int i=0; i<len; i++)
    	{
    		if(dest[dpos+i] != src[i])
    		{
    			return true;
    		}
    	}
    	return false;
    }
    
    public static void shellcmd(final String command)
    {
    	//Process p = Runtime.getRuntime().exec(command);
    	try {
			Runtime.getRuntime().exec(command);
		} 
    	catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
    public static char[] offset(char[] data, int offset)
    {
    	char [] newdata = new char[data.length - offset];
    	System.arraycopy(data, offset, newdata, 0, newdata.length);
    	return newdata;
    }
    
    public static int sizeof(char[] data)
    {
    	return data.length;
    }
    
    public static int sizeof(short[] data)
    {
    	return data.length;
    }
    
    public static char[] charof(char[] data, int len)
    {
    	char[] newdata = new char[data.length - len];
    	System.arraycopy(data, len, newdata, 0, data.length - len);
    	return newdata;
    }
    
    public static int lenof(char[] odata, char[] tdata)
    {
    	return odata.length - tdata.length;
    }
    
    public static void Hash(char[] indata, int len, char[] outdata)
    {
    	byte[] data=new byte[len];
    	for(int i=0; i<len; i++)
    	{
    		data[i] = (byte) indata[i];
    	}
    	outdata = CharUtil.getChars(ShaUtil.sha1(data));
    }

	public static void calc_tdea(char[] timebuf, char[] random, char[] key, int i, int tdeaEncrypt) 
	{
		// TODO Auto-generated method stub
		
	}

	public static void rsa_pub_dec(char[] sendData, int i, int[] sendLen, char[] buff, int j, R_RSA_PUBLIC_KEY[] pinKey) 
	{
		// TODO Auto-generated method stub
		
	}
}